package com.stylefeng.guns.modular.system.service.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.plugins.pagination.Pagination;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.stylefeng.guns.common.constant.Const;
import com.stylefeng.guns.common.persistence.dao.*;
import com.stylefeng.guns.common.persistence.model.*;
import com.stylefeng.guns.core.shiro.ShiroKit;
import com.stylefeng.guns.core.util.DateUtil;
import com.stylefeng.guns.modular.system.business.systemenum.OrderEnum;
import com.stylefeng.guns.modular.system.business.systemenum.OrderFeeEnum;
import com.stylefeng.guns.modular.system.service.ITOrderFeeService;
import com.stylefeng.guns.modular.system.service.ITOrderService;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.*;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author xiejie123
 * @since 2018-01-20
 */
@Service
@Transactional
public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> implements ITOrderService {

    @Autowired
    TOrderMapper orderMapper;
    @Autowired
    DotMapper dotMapper;
    @Autowired
    TTrainMapper tTrainMapper;
    @Autowired
    TBillMapper billMapper;
    @Autowired
    DeptMapper deptMapper;
    @Autowired
    TOrderFeeLogMapper orderFeeLogMapper;
    @Autowired
    TMonthbalanceDetailMapper monthbalanceDetailMapper;
    @Autowired
    TOrderFeeMapper tOrderFeeMapper;
    @Autowired
    ITOrderFeeService itOrderFeeService;
    @Autowired
    private DictMapper tDictMapper;

    @Override
    public List<Map<String, Object>> selectZtAuditeds(Pagination page, String dotId, String name, String is_transfer, String mode) {
        return orderMapper.selectZtAuditeds(page, dotId, name, is_transfer, mode);
    }

    @Override
    public List<Map<String, Object>> selectZtNoOut(Pagination page, String dotId, String name, String is_out, String receipt_status, String receipt, String status, String mode) {
        return orderMapper.selectZtNoOut(page, dotId, name, is_out, receipt_status, receipt, status, mode);
    }

    @Override
    public boolean checkOrder(TOrder order, Integer detp_id, String dotId, Integer user_id) {

        List<Map> mapList = new ArrayList<>();
        int settlement = order.getSettlement() == null ? 1 : order.getSettlement();
            //针对上家
            Map map_f = new HashMap();
            map_f.put("order_id", order.getId());
            map_f.put("detp_id", detp_id);
            map_f.put("dot_id", dotId);
            map_f.put("create_user_id", user_id);
            map_f.put("audit_status", "0");
            map_f.put("fee_id", "22");
            map_f.put("money", order.getPayment() == null ? 0 : order.getPayment());
            //todo 暂时写死 后续要改成读取方式 如果忘记改。。。。
            map_f.put("fee_Income", "1");

            if(order.getIsTransfer().equals("1")){
                Map map_fz = new HashMap();
                map_fz.put("order_id", order.getId());
                map_fz.put("detp_id", detp_id);
                map_fz.put("dot_id", dotId);
                map_fz.put("create_user_id", user_id);
                map_fz.put("audit_status", "0");
                map_fz.put("fee_id", "32");
                map_fz.put("money", order.getPayment() == null ? 0 : order.getPayment());
                //todo 暂时写死 后续要改成读取方式 如果忘记改。。。。
                map_fz.put("fee_Income", "1");

                Map map_cz = new HashMap();
                map_cz.put("order_id", order.getId());
                map_cz.put("detp_id", detp_id);
                map_cz.put("dot_id", dotId);
                map_cz.put("create_user_id", user_id);
                map_cz.put("audit_status", "0");
                map_cz.put("fee_id", "33");
                map_cz.put("money", order.getCollection() == null ? 0 : order.getCollection());
                //todo 暂时写死 后续要改成读取方式 如果忘记改。。。。
                map_cz.put("fee_Income", "1");


                Map map3 = new HashMap();
                map3.put("order_id", order.getId());
                map3.put("detp_id", detp_id);
                map3.put("dot_id", dotId);
                map3.put("create_user_id", user_id);
                map3.put("audit_status", "0");
                map3.put("fee_id", "34");
                map3.put("money", "0");
                //todo 暂时写死 后续要改成读取方式 如果忘记改。。。。
                map3.put("fee_Income", "1");

                Map map4 = new HashMap();
                map4.put("order_id", order.getId());
                map4.put("detp_id", detp_id);
                map4.put("dot_id", dotId);
                map4.put("create_user_id", user_id);
                map4.put("audit_status", "0");
                map4.put("fee_id", "35");
                map4.put("money", "0");
                map4.put("fee_Income", "1");


                Map map5 = new HashMap();
                map5.put("order_id", order.getId());
                map5.put("detp_id", detp_id);
                map5.put("dot_id", dotId);
                map5.put("create_user_id", user_id);
                map5.put("audit_status", "0");
                map5.put("fee_id", "36");
                map5.put("money", "0");
                map5.put("fee_Income", "1");

                Map map6 = new HashMap();
                map6.put("order_id", order.getId());
                map6.put("detp_id", detp_id);
                map6.put("dot_id", dotId);
                map6.put("create_user_id", user_id);
                map6.put("audit_status", "0");
                map6.put("fee_id", "43");
                map6.put("money", order.getExtra_money()==null?"0":order.getExtra_money());
                map6.put("fee_Income", "1");
                mapList.add(map3);
                mapList.add(map4);
                mapList.add(map5);
                mapList.add(map6);
                mapList.add(map_cz);
                mapList.add(map_fz);
            }else{

                Map mapC = new HashMap();
                if(order.getMode()==0){//自提
                    mapC.put("order_id", order.getId());
                    mapC.put("detp_id", detp_id);
                    mapC.put("dot_id", dotId);
                    mapC.put("create_user_id", user_id);
                    if (settlement == 1) {//已清账/待结算 0/1
                        mapC.put("audit_status", "0");
                    } else {
                        mapC.put("audit_status", "3");
                    }
                    mapC.put("fee_id", "2");
                    mapC.put("money", order.getCollection() == null ? 0 : order.getCollection());
                    //todo 暂时写死 后续要改成读取方式 如果忘记改。。。。
                    mapC.put("fee_Income", "0");
                }else{
                    mapC.put("order_id", order.getId());
                    mapC.put("detp_id", detp_id);
                    mapC.put("dot_id", dotId);
                    mapC.put("create_user_id", user_id);
                    if (settlement == 1) {
                        mapC.put("audit_status", "0");
                    } else {
                        mapC.put("audit_status", "3");
                    }
                    mapC.put("fee_id", "38");
                    mapC.put("money", order.getCollection() == null ? 0 : order.getCollection());
                    //todo 暂时写死 后续要改成读取方式 如果忘记改。。。。
                    mapC.put("fee_Income", "0");
//            }


                }

                mapList.add(mapC);
                if(order.getMode()==0){
                    Map map = new HashMap();
                    map.put("order_id", order.getId());
                    map.put("detp_id", detp_id);
                    map.put("dot_id", dotId);
                    map.put("create_user_id", user_id);
                    map.put("audit_status", "0");
                    map.put("fee_id", "1");
                    map.put("money", order.getPayment() == null ? 0 : order.getPayment());
                    //todo 暂时写死 后续要改成读取方式 如果忘记改。。。。
                    map.put("fee_Income", "0");

                    Map mapr = new HashMap();

                    mapr.put("order_id", order.getId());
                    mapr.put("detp_id", detp_id);
                    mapr.put("dot_id", dotId);
                    mapr.put("create_user_id", user_id);
                    mapr.put("audit_status", "0");
                    mapr.put("fee_id", "39");//搬运费
                    mapr.put("money", "0");
                    //todo 暂时写死 后续要改成读取方式 如果忘记改。。。。
                    mapr.put("fee_Income", "0");

                    Map mapb = new HashMap();

                    mapb.put("order_id", order.getId());
                    mapb.put("detp_id", detp_id);
                    mapb.put("dot_id", dotId);
                    mapb.put("create_user_id", user_id);
                    mapb.put("audit_status", "0");
                    mapb.put("fee_id", "40");
                    mapb.put("money", "0");
                    //todo 暂时写死 后续要改成读取方式 如果忘记改。。。。
                    mapb.put("fee_Income", "0");

                    Map mapl = new HashMap();

                    mapl.put("order_id", order.getId());
                    mapl.put("detp_id", detp_id);
                    mapl.put("dot_id", dotId);
                    mapl.put("create_user_id", user_id);
                    mapl.put("audit_status", "0");
                    mapl.put("fee_id", "41");//自提落地费
                    mapl.put("money", order.getExtra_money()==null?"0":order.getExtra_money());
                    mapl.put("fee_Income", "0");

                    mapList.add(map);
                    mapList.add(mapb);
                    mapList.add(mapr);
                    mapList.add(mapl);

                }else {
                     Map mapA = new HashMap();
                    mapA.put("order_id", order.getId());
                    mapA.put("detp_id", detp_id);
                    mapA.put("dot_id", dotId);
                    mapA.put("create_user_id", user_id);
                    mapA.put("audit_status", "0");
                    mapA.put("fee_id", "37");
                    mapA.put("money", order.getPayment() == null ? 0 : order.getPayment());
                    //todo 暂时写死 后续要改成读取方式 如果忘记改。。。。
                    mapA.put("fee_Income", "0");


                    Map mapr = new HashMap();

                    mapr.put("order_id", order.getId());
                    mapr.put("detp_id", detp_id);
                    mapr.put("dot_id", dotId);
                    mapr.put("create_user_id", user_id);
                    mapr.put("audit_status", "0");
                    mapr.put("fee_id", "27");
                    mapr.put("money", "0");
                    //todo 暂时写死 后续要改成读取方式 如果忘记改。。。。
                    mapr.put("fee_Income", "0");

                    Map mapb = new HashMap();

                    mapb.put("order_id", order.getId());
                    mapb.put("detp_id", detp_id);
                    mapb.put("dot_id", dotId);
                    mapb.put("create_user_id", user_id);
                    mapb.put("audit_status", "0");
                    mapb.put("fee_id", "28");
                    mapb.put("money",  "0");
                    //todo 暂时写死 后续要改成读取方式 如果忘记改。。。。
                    mapb.put("fee_Income", "0");

                    Map map1 = new HashMap();

                    map1.put("order_id", order.getId());
                    map1.put("detp_id", detp_id);
                    map1.put("dot_id", dotId);
                    map1.put("create_user_id", user_id);
                    map1.put("audit_status", "0");
                    map1.put("fee_id", "29");
                    map1.put("money", "0");
                    //todo 暂时写死 后续要改成读取方式 如果忘记改。。。。
                    map1.put("fee_Income", "0");

                    Map map2 = new HashMap();

                    map2.put("order_id", order.getId());
                    map2.put("detp_id", detp_id);
                    map2.put("dot_id", dotId);
                    map2.put("create_user_id", user_id);
                    map2.put("audit_status", "0");
                    map2.put("fee_id", "30");
                    map2.put("money", "0");
                    //todo 暂时写死 后续要改成读取方式 如果忘记改。。。。
                    map2.put("fee_Income", "1");

                    Map mapl = new HashMap();

                    mapl.put("order_id", order.getId());
                    mapl.put("detp_id", detp_id);
                    mapl.put("dot_id", dotId);
                    mapl.put("create_user_id", user_id);
                    mapl.put("audit_status", "0");
                    mapl.put("fee_id", "42");//配送落地费
                    mapl.put("money", order.getExtra_money()==null?"0":order.getExtra_money());
                    mapl.put("fee_Income", "0");

                    mapList.add(map1);
                    mapList.add(mapA);
                    mapList.add(map2);
                    mapList.add(mapb);
                    mapList.add(mapr);
                    mapList.add(mapl);

                }
            }
            mapList.add(map_f);

        Map map3 = new HashMap(); // 中转费
        map3.put("order_id", order.getId());
        map3.put("detp_id", detp_id);
        map3.put("dot_id", dotId);
        map3.put("create_user_id", user_id);
        map3.put("audit_status", "0");

        map3.put("fee_id", "24");
        map3.put("money", order.getScene_money() == null ? 0 : order.getScene_money());
        //todo 暂时写死 后续要改成读取方式 如果忘记改。。。。
        map3.put("fee_Income", "0");
        mapList.add(map3);

        Map mape2 = new HashMap();
        mape2.put("order_id", order.getId());
        mape2.put("detp_id", detp_id);
        mape2.put("dot_id", dotId);
        mape2.put("create_user_id", user_id);
        if (settlement == 1) {
            mape2.put("audit_status", "0");
        } else {
            mape2.put("audit_status", "3");
        }
        mape2.put("fee_id", "23");
        mape2.put("money", order.getCollection() == null ? 0 : order.getCollection());
        //todo 暂时写死 后续要改成读取方式 如果忘记改。。。。
        mape2.put("fee_Income", "1");
        mapList.add(mape2);

        //送货
        if(order.getTransport_money()!=null&&!order.getTransport_money().isEmpty()&&!"null".equals(order.getTransport_money())){
            float transport_money=Float.valueOf(order.getTransport_money());
            Map map_t = new HashMap();
            map_t.put("order_id", order.getId());
            map_t.put("detp_id", detp_id);
            map_t.put("dot_id", dotId);
            map_t.put("create_user_id", user_id);
            map_t.put("audit_status", "0");
            map_t.put("fee_id", "25");
            map_t.put("money",transport_money);
            //todo 暂时写死 后续要改成读取方式 如果忘记改。。。。
            map_t.put("fee_Income", "0");

            mapList.add(map_t);

        }else{
            Map map_t = new HashMap();
            map_t.put("order_id", order.getId());
            map_t.put("detp_id", detp_id);
            map_t.put("dot_id", dotId);
            map_t.put("create_user_id", user_id);
            map_t.put("audit_status", "0");
            map_t.put("fee_id", "25");
            map_t.put("money","0");
            map_t.put("fee_Income", "0");
            mapList.add(map_t);
        }

        //搬运
        if(order.getCarry_money()!=null&&!order.getCarry_money().isEmpty()&&!"null".equals(order.getCarry_money())){
            float carry_money=Float.valueOf(order.getCarry_money());
            Map map_t = new HashMap();
            map_t.put("order_id", order.getId());
            map_t.put("detp_id", detp_id);
            map_t.put("dot_id", dotId);
            map_t.put("create_user_id", user_id);
            map_t.put("audit_status", "0");
            map_t.put("fee_id", "26");
            map_t.put("money", carry_money);
            //todo 暂时写死 后续要改成读取方式 如果忘记改。。。。
            map_t.put("fee_Income", "0");
            mapList.add(map_t);

        }else{
            Map map_t = new HashMap();
            map_t.put("order_id", order.getId());
            map_t.put("detp_id", detp_id);
            map_t.put("dot_id", dotId);
            map_t.put("create_user_id", user_id);
            map_t.put("audit_status", "0");
            map_t.put("fee_id", "26");
            map_t.put("money", "0");
            //todo 暂时写死 后续要改成读取方式 如果忘记改。。。。
            map_t.put("fee_Income", "0");
            mapList.add(map_t);
        }
        if (mapList.size() > 0) {
            int adds = orderMapper.addOrderFee(mapList);
        }
        return true;
    }

    @Override
    public boolean addAndTrian(String ids, TTrain tTrain,String cf,List<Map> fees) {
        tTrainMapper.insert(tTrain);//插入批次表
        for (Map map : fees) {
            String log_no= DateUtil.getAllTimes();
            TOrder order=new TOrder();
            order.setId(Integer.valueOf(map.get("id").toString()));
            order.setTrain_id(tTrain.getId());
            order.setFee_remark(map.get("fee_remark")==null?"":map.get("fee_remark").toString());
            order.setTrain_no(tTrain.getTrainNo());
            order.setStatus(2);
            order.setFlow_status(2);//0 开单 1 车次核销 2 出库 3 收银 4 核销
            orderMapper.updateById(order);
            orderMapper.addUseFeeLogs(log_no, ShiroKit.getUser().getId()+ "",tTrain.getTrainNo(),"3");//加入操作日志
            orderMapper.delUseFee(tTrain.getTrainNo(),"3");//删除原有的费用
        }
        List<Map> mapList = new ArrayList<>();
        for (Map map : fees) {
            //  提付
            Map param = new HashMap();
            param.put("order_id", map.get("id").toString());
            param.put("detp_id", ShiroKit.getUser().getDeptId());
            param.put("dot_id", tTrain.getDot_id());
            param.put("create_user_id", ShiroKit.getUser().getId());
            param.put("audit_status", "0");
            param.put("fee_id", map.get("paymentId").toString());
            param.put("money", map.get("payment").toString());
            param.put("fee_Income", "0");
            param.put("pay_mode", "0");
            param.put("settlement_type","0");
            mapList.add(param);
            Map param1 = new HashMap();
            param1.put("order_id", map.get("id").toString());
            param1.put("detp_id", ShiroKit.getUser().getDeptId());
            param1.put("dot_id", tTrain.getDot_id());
            param1.put("create_user_id", ShiroKit.getUser().getId());
            param1.put("audit_status", "0");
            param1.put("fee_id", map.get("collectionId").toString());
            param1.put("money", map.get("collection").toString());
            param1.put("fee_Income", "0");
            param1.put("pay_mode", "0");
            param1.put("settlement_type","0");
            mapList.add(param1);
            Map param2= new HashMap();
            param2.put("order_id", map.get("id").toString());
            param2.put("detp_id", ShiroKit.getUser().getDeptId());
            param2.put("dot_id", tTrain.getDot_id());
            param2.put("create_user_id", ShiroKit.getUser().getId());
            param2.put("audit_status", "0");
            param2.put("fee_id", map.get("shfId").toString());
            param2.put("money", map.get("shf").toString());
            param2.put("fee_Income", "0");
            param2.put("pay_mode", "0");
            param2.put("settlement_type","0");
            mapList.add(param2);
            Map param3= new HashMap();
            param3.put("order_id", map.get("id").toString());
            param3.put("detp_id", ShiroKit.getUser().getDeptId());
            param3.put("dot_id", tTrain.getDot_id());
            param3.put("create_user_id", ShiroKit.getUser().getId());
            param3.put("audit_status", "0");
            param3.put("fee_id", map.get("byfId").toString());
            param3.put("money", map.get("byf").toString());
            param3.put("fee_Income", "0");
            param3.put("pay_mode", "0");
            param3.put("settlement_type","0");
            mapList.add(param3);
            Map param4= new HashMap();
            param4.put("order_id", map.get("id").toString());
            param4.put("detp_id", ShiroKit.getUser().getDeptId());
            param4.put("dot_id", tTrain.getDot_id());
            param4.put("create_user_id", ShiroKit.getUser().getId());
            param4.put("audit_status", "0");
            param4.put("fee_id", map.get("ccfId").toString());
            param4.put("money", map.get("ccf").toString());
            param4.put("fee_Income", "0");
            param4.put("pay_mode", "0");
            param4.put("settlement_type","0");
            mapList.add(param4);
            Map param5= new HashMap();
            param5.put("order_id", map.get("id").toString());
            param5.put("detp_id", ShiroKit.getUser().getDeptId());
            param5.put("dot_id", tTrain.getDot_id());
            param5.put("create_user_id", ShiroKit.getUser().getId());
            param5.put("audit_status", "0");
            param5.put("fee_id", map.get("cfId").toString());
            param5.put("money", map.get("cf").toString());
            param5.put("fee_Income", "0");
            param5.put("pay_mode", "0");
            param5.put("settlement_type","0");
            mapList.add(param5);
            Map param6= new HashMap();
            param6.put("order_id", map.get("id").toString());
            param6.put("detp_id", ShiroKit.getUser().getDeptId());
            param6.put("dot_id", tTrain.getDot_id());
            param6.put("create_user_id", ShiroKit.getUser().getId());
            param6.put("audit_status", "0");
            param6.put("fee_id", map.get("extra_moneyid").toString());
            param6.put("money", map.get("extra_money").toString());
            param6.put("fee_Income", "0");
            param6.put("pay_mode", "0");
            param6.put("settlement_type","0");
            mapList.add(param6);
       }
        if (mapList.size() > 0) {
            int adds = orderMapper.addOrderFee(mapList);
        }
       return true;
    }



    @Override
    public boolean addAndTRTrian(TBill bill,String ids, TTrain tTrain, String cf, List<Map> fees, String mA, String mB, String mC, String mD, String mE,String mF,String xj,String  transfer_name,String gz) {
        if(gz!=null&&"0".equals(gz)){
            //无挂帐 车次无需核销
            tTrain.setStatus(1);// 0 未核销 1 核销 2 配送  3已付款

        }else{
            tTrain.setStatus(0);// 0 未核销 1 核销 2 配送  3已付款
        }
        billMapper.insert(bill);
        tTrainMapper.insert(tTrain);//插入批次表

        Map para=new HashMap();
        para.put("dot_id",ShiroKit.getUser().getDotId());
        para.put("nType", Const.NTYPE_04); // 类别 00 初始 01 配送 02 中转 03 自提  04 月结
        TMonthbalanceDetail m=new TMonthbalanceDetail();
        m.setCreater(ShiroKit.getUser().getId());
        m.setDotId(ShiroKit.getUser().getDotId());
        m.setIncome(4);//来源 1，收货，2，自提，3，配送，4，中转，5，改单
        m.setStatus("1");//0待结算 1 已结算
        m.setSettlementType(0);//付款方式，0现结 1月结
        m.setMoney(Double.parseDouble(xj));
        m.setTraner(transfer_name);
        m.setIncomeId(tTrain.getId());
        m.setIncomeName(tTrain.getTrainNo());
        m.setBillId(bill.getId());
        m.setBalance_num(tDictMapper.getNumCode(para));
        monthbalanceDetailMapper.insert(m);


        String strId[]=ids.split(",");
        for (int i = 0; i < strId.length; i++) {
            TOrder order=new TOrder();
            order.setId(Integer.valueOf(strId[i]));
            order.setTrain_id(tTrain.getId());
            order.setTrain_no(tTrain.getTrainNo());
            if(gz!=null&&"0".equals(gz)){
                //无月结费用 无需核销
                order.setStatus(3);
                //订单状态 0-审核中 1-待出库 2-已出库 3-完成
                order.setFlow_status(4);//0 开单 1 车次核销 2 出库 3 收银 4 核销
            }else{
                order.setStatus(2);
                order.setCheck_time(new Date());
                //订单状态 0-审核中 1-待出库 2-已出库 3-完成
                order.setFlow_status(3);//0 开单 1 车次核销 2 出库 3 收银 4 核销
            }

            order.setTransfer_name(transfer_name);
            orderMapper.updateById(order);
            String log_no= DateUtil.getAllTimes();
            orderMapper.addUseFeeLogs(log_no, ShiroKit.getUser().getId()+ "",tTrain.getTrainNo(),"6");//加入操作日志
            orderMapper.delUseFee(tTrain.getTrainNo(),"6");//删除原有的费用
        }

        List<Map> mapList = new ArrayList<>();
        List<String> mIds=new ArrayList<>();
        for (Map map : fees) {
            //  提付
            Map param = new HashMap();
            param.put("order_id", map.get("id").toString());
            param.put("detp_id", ShiroKit.getUser().getDeptId());
            param.put("dot_id", tTrain.getDot_id());
            param.put("create_user_id", ShiroKit.getUser().getId());
            if(gz!=null&&"0".equals(gz)){
                param.put("audit_status", "3");
            }else{
                param.put("audit_status", "1");
            }
            param.put("fee_id", map.get("paymentId").toString());
            param.put("money", map.get("payment").toString());
            param.put("fee_Income", "0");
            param.put("pay_mode", "0");
            if(mA.equals("0")){
                param.put("settlement_type","0");
                param.put("balance_id",m.getId());
            }else{
                param.put("settlement_type","1");
                //param.put("balance_id","");
            }
            mapList.add(param);

            Map param1 = new HashMap();
            param1.put("order_id", map.get("id").toString());
            param1.put("detp_id", ShiroKit.getUser().getDeptId());
            param1.put("dot_id", tTrain.getDot_id());
            param1.put("create_user_id", ShiroKit.getUser().getId());
            if(gz!=null&&"0".equals(gz)){
                param1.put("audit_status", "3");
            }else{
                param1.put("audit_status", "1");
            }
            param1.put("fee_id", map.get("collectionId").toString());
            param1.put("money", map.get("collection").toString());
            param1.put("fee_Income", "0");
            param1.put("pay_mode", "0");
            if(mB.equals("0")){
                param1.put("settlement_type","0");
                param1.put("balance_id",m.getId());
            }else{
                param1.put("settlement_type","1");
            }
            mapList.add(param1);


            Map param2= new HashMap();
            param2.put("order_id", map.get("id").toString());
            param2.put("detp_id", ShiroKit.getUser().getDeptId());
            param2.put("dot_id", tTrain.getDot_id());
            param2.put("create_user_id", ShiroKit.getUser().getId());
            if(gz!=null&&"0".equals(gz)){
                param2.put("audit_status", "3");
            }else{
                param2.put("audit_status", "1");
            }
            param2.put("fee_id", map.get("zzId").toString());
            param2.put("money", map.get("zz").toString());
            param2.put("fee_Income", "0");
            param2.put("pay_mode", "0");
            if(mC.equals("0")){
                param2.put("settlement_type","0");
                param2.put("balance_id",m.getId());
            }else{
                param2.put("settlement_type","1");
            }
            mapList.add(param2);


            Map param3= new HashMap();
            param3.put("order_id", map.get("id").toString());
            param3.put("detp_id", ShiroKit.getUser().getDeptId());
            param3.put("dot_id", tTrain.getDot_id());
            param3.put("create_user_id", ShiroKit.getUser().getId());
            if(gz!=null&&"0".equals(gz)){
                param3.put("audit_status", "3");
            }else{
                param3.put("audit_status", "1");
            }
            param3.put("fee_id", map.get("byfId").toString());
            param3.put("money", map.get("ty").toString());
            param3.put("fee_Income", "0");
            param3.put("pay_mode", "0");
            if(mE.equals("0")){//搬运费
                param3.put("settlement_type","0");
                param3.put("balance_id",m.getId());
            }else{
                param3.put("settlement_type","1");
            }
            mapList.add(param3);

            Map param4= new HashMap();
            param4.put("order_id", map.get("id").toString());
            param4.put("detp_id", ShiroKit.getUser().getDeptId());
            param4.put("dot_id", tTrain.getDot_id());
            param4.put("create_user_id", ShiroKit.getUser().getId());
            if(gz!=null&&"0".equals(gz)){
                param4.put("audit_status", "3");
            }else{
                param4.put("audit_status", "1");
            }
            param4.put("fee_id", map.get("shfId").toString());
            param4.put("money", map.get("sh").toString());
            param4.put("fee_Income", "0");
            param4.put("pay_mode", "0");
            if(mD.equals("0")){//送货费
                param4.put("settlement_type","0");
                param4.put("balance_id",m.getId());
            }else{
                param4.put("settlement_type","1");
            }
            mapList.add(param4);

            Map param5= new HashMap();
            param5.put("order_id", map.get("id").toString());
            param5.put("detp_id", ShiroKit.getUser().getDeptId());
            param5.put("dot_id", tTrain.getDot_id());
            param5.put("create_user_id", ShiroKit.getUser().getId());
            if(gz!=null&&"0".equals(gz)){
                param5.put("audit_status", "3");
            }else{
                param5.put("audit_status", "1");
            }
            param5.put("fee_id", map.get("extra_moneyid").toString());
            param5.put("money", map.get("extra_money").toString());
            param5.put("fee_Income", "0");
            param5.put("pay_mode", "0");
            if(mF.equals("0")){//落地费
                param5.put("settlement_type","0");
                param5.put("balance_id",m.getId());
            }else{
                param5.put("settlement_type","1");
            }
            mapList.add(param5);


        }
        if (mapList.size() > 0) {
            int adds = orderMapper.addOrderFee(mapList);
        }
        return true;
    }

    @Override
    public List<Map<String, Object>> selectOrderList(Page<Map<String, Object>> page, Map m) {
        return orderMapper.selectOrderList(page,m);
    }

    /**
     *  自提在库数据
     */
    @Override
    public List<Map<String, Object>> selectSelfLiftInStoreHouse(Page<Map<String, Object>> page, String dot_id, String name, String is_out, String mRStatus, String receipt, String status, String flag) {
        return orderMapper.selectSelfLiftInStoreHouse(page, dot_id,  name,is_out,mRStatus, receipt, status,flag);
    }

    @Override
    public List<Map<String, Object>> selectSelfLiftDataList(Page<Map<String, Object>> page, List<Integer> list) {
        return orderMapper.selectSelfLiftDataList(page,list);
    }



    @Override
    public List<Map<String, Object>> getFee(String deptid) {
        return orderMapper.getFee(deptid);
    }

    @Override
    public List<Map<String, Object>> getOrderFee(String order_id) {
        return orderMapper.getOrderFee(order_id);
    }

    @Override
    public boolean opOrderFee(List<Map> maps, Integer detp_id, Integer user_id, String log_no, String order_id) {
        orderMapper.addOrderFeeLogs(log_no, user_id + "", order_id);//加入操作日志
        orderMapper.delOrderFee(order_id);//删除原有的费用
        List<Map> mapList = new ArrayList<>();
        for (Map map : maps) {
            Map param = new HashMap();
            param.put("order_id", map.get("order_id").toString());
            param.put("detp_id", detp_id);
            param.put("dot_id", map.get("dot_id").toString());
            param.put("create_user_id", user_id);
            param.put("audit_status", "0");
            param.put("fee_id", map.get("fee_id").toString());
            param.put("money", map.get("fee_money").toString());
            param.put("fee_Income", map.get("fee_Income").toString());
            param.put("pay_mode", map.get("fee_pay_mode").toString());
            param.put("settlement_type", map.get("fee_settlement").toString());
            mapList.add(param);
        }
        if (mapList.size() > 0) {
            int adds = orderMapper.addOrderFee(mapList);
        }
        TOrder order=new TOrder();
        order.setId(Integer.valueOf(order_id));
        order.setStatus(2);
        orderMapper.updateById(order);
        return false;
    }

    @Override
    public boolean opOrderFeeSuper(List<Map> maps, Integer detp_id, Integer user_id, String log_no, String order_id) {
        orderMapper.addOrderFeeLogs(log_no, user_id + "", order_id);//加入操作日志
        orderMapper.delOrderFee(order_id);//删除原有的费用
        List<Map> mapList = new ArrayList<>();
        for (Map map : maps) {
            Map param = new HashMap();
            param.put("order_id", map.get("order_id").toString());
            param.put("detp_id", detp_id);
            param.put("dot_id", map.get("dot_id").toString());
            param.put("create_user_id", user_id);
            param.put("audit_status", "3");
            param.put("fee_id", map.get("fee_id").toString());
            param.put("money", map.get("fee_money").toString());
            param.put("fee_Income", map.get("fee_Income").toString());
            param.put("pay_mode", map.get("fee_pay_mode").toString());
            param.put("settlement_type", map.get("fee_settlement").toString());
            mapList.add(param);
        }
        if (mapList.size() > 0) {
            int adds = orderMapper.addOrderFee(mapList);
        }
        return false;
    }

    @Override
    public List<Map<String, Object>> selectTransfer(Pagination page, String dotId, String name, String receipt_status, String receipt, String status, String province_code, String city_code, String area_code) {
        return orderMapper.selectTransfer(page, dotId, name, receipt_status, receipt, status, province_code, city_code, area_code);
    }

    @Override
    public List<Map<String, Object>> getTransferOrders(List<Integer> ids) {
        return orderMapper.getTransferOrders(ids);
    }

    @Override
    public List<Map<String, Object>> selectDisOutList(Pagination page,List<Integer> ids) {
        return orderMapper.selectDisOutList(page,ids);
    }

    @Override
    public List<Map<String, Object>> selectZZOutList(Pagination page, List<Integer> ids) {
        return orderMapper.selectZZOutList(page,ids);
    }

    @Override
    public List<Map<String, Object>> selectDriverList(String dept_id) {
        return orderMapper.selectDriverList(dept_id);
    }

    @Override
    public List<Map<String, Object>> selectReport(Pagination page,Map param) {
        return orderMapper.selectReport(page,param);
    }
    @Override
    public List<Map<String, Object>> selectReportAvg(Map param) {
        return orderMapper.selectReportAvg(param);
    }

    @Override
    public boolean export(String filepath, String returnpath, List<Map<String, Object>> orders) {
        try {
            File file = new File(filepath);
            if (!file.exists()) {
                if (!file.createNewFile()) {
                    throw new IOException("文件创建失败");
                }
            }
            //创建HSSFWorkbook对象(excel的文档对象)
            HSSFWorkbook wb = new HSSFWorkbook();
            //建立新的sheet对象（excel的表单）
            HSSFSheet sheet = wb.createSheet("Sheet1");
            //在sheet里创建第一行，参数为行索引(excel的行)，可以是0～65535之间的任何一个
            HSSFRow row1 = sheet.createRow(0);
            //创建单元格（excel的单元格，参数为列索引，可以是0～255之间的任何一个
            HSSFCell cell = row1.createCell(0);
            //设置单元格内容
            //     cell.setCellValue(" );
            //合并单元格CellRangeAddress构造参数依次表示起始行，截至行，起始列， 截至列
            //     sheet.addMergedRegion(new CellRangeAddress(0,0,0,3));
            //在sheet里创建第二行
            HSSFRow row2 = sheet.createRow(0);
            //创建单元格并设置单元格内容
            row2.createCell(0).setCellValue("编号");
            row2.createCell(1).setCellValue("上游物流");
            row2.createCell(2).setCellValue("收货地址");
            row2.createCell(3).setCellValue("收货人");
            row2.createCell(4).setCellValue("物品名称");
            row2.createCell(5).setCellValue("配送方式");
            row2.createCell(6).setCellValue("件数");
            row2.createCell(7).setCellValue("回单要求");
            row2.createCell(8).setCellValue("订单状态");
            row2.createCell(9).setCellValue("上游款");
            row2.createCell(10).setCellValue("下游款款");
            row2.createCell(11).setCellValue("利润");
            row2.createCell(12).setCellValue("司机运费");
            row2.createCell(13).setCellValue("入库时间");

            for (int i = 0; i < orders.size(); i++) {
                HSSFRow row3 = sheet.createRow(i + 1);
                row3.createCell(0).setCellValue(orders.get(i).get("originalNum").toString());
                row3.createCell(1).setCellValue(orders.get(i).get("sendDeptName")==null?"":orders.get(i).get("sendDeptName").toString());
                row3.createCell(2).setCellValue(orders.get(i).get("recAddress")==null?"":orders.get(i).get("recAddress").toString());
                row3.createCell(3).setCellValue(orders.get(i).get("consignee")==null?"":orders.get(i).get("consignee").toString());
                row3.createCell(4).setCellValue(orders.get(i).get("goodsName")==null?"":orders.get(i).get("goodsName").toString());
                if(orders.get(i).get("isTransfer").toString().equals("1")){
                    row3.createCell(5).setCellValue("中转");
                }else{
                    if(orders.get(i).get("MODE").toString().equals("0")){
                        row3.createCell(5).setCellValue("自提");
                    }else{
                        row3.createCell(5).setCellValue("配送");
                    }
                }

                row3.createCell(6).setCellValue(orders.get(i).get("goodsPiece").toString());
                row3.createCell(7).setCellValue(orders.get(i).get("receipt")==null?"":orders.get(i).get("receipt").toString());

                switch (orders.get(i).get("flow_status")==null?"":orders.get(i).get("flow_status").toString()){
                    case "0":
                        row3.createCell(8).setCellValue("开单");
                        break;
                    case "1":
                        row3.createCell(8).setCellValue("库存");
                        break;
                    case "2":
                        row3.createCell(8).setCellValue("出库");
                        break;
                    case "3":
                        row3.createCell(8).setCellValue("收银");
                        break;
                    case "4":
                        row3.createCell(8).setCellValue("核销");
                        break;
                    default:
                        row3.createCell(8).setCellValue("");
                        break;
                }

                row3.createCell(9).setCellValue(orders.get(i).get("sy").toString());
                row3.createCell(10).setCellValue(orders.get(i).get("xy").toString());
                row3.createCell(11).setCellValue(Float.valueOf(orders.get(i).get("sy").toString())+Float.valueOf(orders.get(i).get("xy").toString()));
                row3.createCell(12).setCellValue(orders.get(i).get("sjyf").toString());
                row3.createCell(13).setCellValue(orders.get(i).get("createtime").toString());
            }
            FileOutputStream fout = new FileOutputStream(filepath);
            wb.write(fout);
            fout.close();
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    @Override
    public boolean exportOrderBack(String filepath, String returnpath, List<Map<String, Object>> orders) {
        try {
            File file = new File(filepath);
            if (!file.exists()) {
                if (!file.createNewFile()) {
                    throw new IOException("文件创建失败");
                }
            }
            //创建HSSFWorkbook对象(excel的文档对象)
            HSSFWorkbook wb = new HSSFWorkbook();
            //建立新的sheet对象（excel的表单）
            HSSFSheet sheet = wb.createSheet("Sheet1");
            //在sheet里创建第一行，参数为行索引(excel的行)，可以是0～65535之间的任何一个
            HSSFRow row1 = sheet.createRow(0);
            //创建单元格（excel的单元格，参数为列索引，可以是0～255之间的任何一个
            HSSFCell cell = row1.createCell(0);
            //设置单元格内容
            //     cell.setCellValue(" );
            //合并单元格CellRangeAddress构造参数依次表示起始行，截至行，起始列， 截至列
            //     sheet.addMergedRegion(new CellRangeAddress(0,0,0,3));
            //在sheet里创建第二行
            HSSFRow row2 = sheet.createRow(0);
            //创建单元格并设置单元格内容
            row2.createCell(0).setCellValue("上游网点");
            row2.createCell(1).setCellValue("单号");
            row2.createCell(2).setCellValue("回单要求");
            row2.createCell(3).setCellValue("回单状态");
            row2.createCell(4).setCellValue("运单类型");
            row2.createCell(5).setCellValue("收货人");
            row2.createCell(6).setCellValue("货物名称");
            row2.createCell(7).setCellValue("件数");
            row2.createCell(8).setCellValue("入库时间");
            row2.createCell(9).setCellValue("中转地址");
            row2.createCell(10).setCellValue("接收时间");
            row2.createCell(11).setCellValue("发送时间");
            row2.createCell(12).setCellValue("发送方式");

            for (int i = 0; i < orders.size(); i++) {
                HSSFRow row3 = sheet.createRow(i + 1);
                row3.createCell(0).setCellValue(orders.get(i).get("send_dept_name").toString());
                row3.createCell(1).setCellValue(orders.get(i).get("original_num")==null?"":orders.get(i).get("original_num").toString());
                row3.createCell(2).setCellValue(orders.get(i).get("receipt")==null?"":orders.get(i).get("receipt").toString());
//                row3.createCell(3).setCellValue(orders.get(i).get("consignee")==null?"":orders.get(i).get("consignee").toString());
//                row3.createCell(4).setCellValue(orders.get(i).get("goodsName")==null?"":orders.get(i).get("goodsName").toString());
                if(orders.get(i).get("receipt_status").toString().equals("0")){
                    row3.createCell(3).setCellValue("待办");
                }else if(orders.get(i).get("receipt_status").toString().equals("1")){
                    row3.createCell(3).setCellValue("已收");
                }else if(orders.get(i).get("receipt_status").toString().equals("1")){
                    row3.createCell(3).setCellValue("已完成");
                }else{
                    row3.createCell(3).setCellValue("无需处理");
                }
                if(orders.get(i).get("is_transfer").toString().equals("1")){
                    row3.createCell(4).setCellValue("中转");
                }else{
                    if(orders.get(i).get("mode").toString().equals("0")){
                        row3.createCell(4).setCellValue("自提");
                    }else{
                        row3.createCell(4).setCellValue("配送");
                    }
                }

                row3.createCell(5).setCellValue(orders.get(i).get("consignee")==null?"":orders.get(i).get("consignee").toString());
                row3.createCell(6).setCellValue(orders.get(i).get("goods_name")==null?"":orders.get(i).get("goods_name").toString());
                row3.createCell(7).setCellValue(orders.get(i).get("goods_piece")==null?"":orders.get(i).get("goods_piece").toString());
                row3.createCell(8).setCellValue(orders.get(i).get("createtime")==null?"":orders.get(i).get("createtime").toString());
                row3.createCell(9).setCellValue(orders.get(i).get("recAddress")==null?"":orders.get(i).get("recAddress").toString());
                row3.createCell(10).setCellValue(orders.get(i).get("receive_time")==null?"":orders.get(i).get("receive_time").toString());
                row3.createCell(11).setCellValue(orders.get(i).get("send_time")==null?"":orders.get(i).get("send_time").toString());
                row3.createCell(12).setCellValue(orders.get(i).get("process_method")==null?"":orders.get(i).get("process_method").toString());
            }
            FileOutputStream fout = new FileOutputStream(filepath);
            wb.write(fout);
            fout.close();
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }


    @Override
    public Map<String, Object> indexNum(Map param) {
        return orderMapper.indexNum(param);
    }

    @Override
    public List<Map<String, Object>> selectOrders(String query,String dot_id) {
        return orderMapper.selectOrders(query,dot_id);
    }

    @Override
    public List<Map<String, Object>> selectSuperOrder(Pagination page,Map param) {
        return orderMapper.selectSuperOrder(page,param);
    }


    @Override
    public boolean checkOrder(Integer id, Integer detp_id, String dotId, Integer user_id) {
        return false;
    }

    /**
     * 自提单重新入库
     * @param   order_id
     */
    @Override
    public void revokeOrder(String order_id) {
        //1，回退订单状态
        TOrder tOrder=new TOrder();
        tOrder.setId(Integer.parseInt(order_id));
        tOrder.setStatus(1);//订单状态 0-审核中 1-待出库 2-已出库 3-完成
        tOrder.setFlow_status(1); //0 开单 1 车次核销 2 出库 3 收银 4 核销
        orderMapper.updateById(tOrder);
        //删除t_bill
        billMapper.recordBackUp(order_id);
        List<TBill> list= billMapper.selectBillByOrderId(order_id);
        for(TBill t:list){
            billMapper.deleteById(t.getId());
        }
        //回退现结数据
        monthbalanceDetailMapper.recordBackUp(order_id);
        //删除月结费用
        monthbalanceDetailMapper.delMonthBalanceBackUp(order_id);
        // 回退原有费用
        tOrderFeeMapper.revokeOrderFee(order_id);
    }

    /**
     * 自提单新增配送子单
     */
    @Override
    public void addSubDelivery(Integer id, Double tff, Double dshk, Double ldf, Double shf, Double byf, Double ccf,String  original_num) {
       TOrder tOrder=orderMapper.selectById(id);
        TOrder tOrderSub=new TOrder();
        BeanUtils.copyProperties(tOrder, tOrderSub);
        tOrderSub.setId(null);
        tOrderSub.setMode(OrderEnum.ORDER_MODE_DELIVERY.getCode());//自提/配送 0/1
        tOrderSub.setReceipt("");
        tOrderSub.setOrderNum("PS"+ DateUtil.getAllTimes());
        tOrderSub.setOriginal_num(original_num);
        tOrderSub.setIsTransfer(OrderEnum.ORDER_TRANSFER_NO.getCode()+"");//是否中转 0 否 1 是
        tOrderSub.setReceiptStatus(OrderEnum.ORDER_BACK_UNNECESSARY.getCode());//回单状态 0 待回单  1.已回寄,2,已完成,3无需回单
        tOrderSub.setStatus(OrderEnum.ORDER_STATUS_IN_WAREHOUSE.getCode());//订单状态 0-审核中 1-待出库 2-已出库 3-完成
        tOrderSub.setPush_str("");
        tOrderSub.setReallyUser("");
        tOrderSub.setReallyCard("");
        tOrderSub.setCall_str("");
        tOrderSub.setBill_num("");
        tOrderSub.setBill_id(null);
        tOrderSub.setOrder_back_receive_id(null);
        tOrderSub.setOrder_back_send_id(null);
        tOrderSub.setFlow_status(OrderEnum.FLOW_ORDER_TRAIN_CHECK.getCode());
        tOrderSub.setExtra_money(null);
        tOrderSub.setCreatetime(new Date());
        tOrderSub.setNotification_time(null);
        orderMapper.insert(tOrderSub);

      //新增费用 上游费用均为0 配送费用根据页面填写数据生成
        List<TOrderFee> tOrderFees=new ArrayList<TOrderFee>();
        //上游费用
        //提付
        TOrderFee torderFee_tff=new TOrderFee();
        torderFee_tff.setOrderId(tOrderSub.getId());
        torderFee_tff.setDetpId(ShiroKit.getUser().getDeptId());
        torderFee_tff.setDotId(ShiroKit.getUser().getDotId());
        torderFee_tff.setCreateUserId(ShiroKit.getUser().getId());
        torderFee_tff.setAuditStatus(OrderFeeEnum.AUDIT_BALANCE.getCode());
        torderFee_tff.setFeeId(OrderFeeEnum.SENDER_TF_FEE.getCode());
        torderFee_tff.setMoney(0.0);
        tOrderFees.add(torderFee_tff);
        //代收货款
        TOrderFee torderFee_dshk=new TOrderFee();
        torderFee_dshk.setOrderId(tOrderSub.getId());
        torderFee_dshk.setDetpId(ShiroKit.getUser().getDeptId());
        torderFee_dshk.setDotId(ShiroKit.getUser().getDotId());
        torderFee_dshk.setCreateUserId(ShiroKit.getUser().getId());
        torderFee_dshk.setAuditStatus(OrderFeeEnum.AUDIT_BALANCE.getCode());
        torderFee_dshk.setFeeId(OrderFeeEnum.SENDER_DSHK_FEE.getCode());
        torderFee_dshk.setMoney(0.0);
        tOrderFees.add(torderFee_dshk);
        //中转费
        TOrderFee torderFee_zzf=new TOrderFee();
        torderFee_zzf.setOrderId(tOrderSub.getId());
        torderFee_zzf.setDetpId(ShiroKit.getUser().getDeptId());
        torderFee_zzf.setDotId(ShiroKit.getUser().getDotId());
        torderFee_zzf.setCreateUserId(ShiroKit.getUser().getId());
        torderFee_zzf.setAuditStatus(OrderFeeEnum.AUDIT_BALANCE.getCode());
        torderFee_zzf.setFeeId(OrderFeeEnum.SENDER_ZZ_FEE.getCode());
        torderFee_zzf.setMoney(0.0);
        tOrderFees.add(torderFee_zzf);
        //送货费
        TOrderFee torderFee_sh=new TOrderFee();
        torderFee_sh.setOrderId(tOrderSub.getId());
        torderFee_sh.setDetpId(ShiroKit.getUser().getDeptId());
        torderFee_sh.setDotId(ShiroKit.getUser().getDotId());
        torderFee_sh.setCreateUserId(ShiroKit.getUser().getId());
        torderFee_sh.setAuditStatus(OrderFeeEnum.AUDIT_BALANCE.getCode());
        torderFee_sh.setFeeId(OrderFeeEnum.SENDER_SH_FEE.getCode());
        torderFee_sh.setMoney(0.0);
        tOrderFees.add(torderFee_sh);
        //搬运费
        TOrderFee torderFee_by=new TOrderFee();
        torderFee_by.setOrderId(tOrderSub.getId());
        torderFee_by.setDetpId(ShiroKit.getUser().getDeptId());
        torderFee_by.setDotId(ShiroKit.getUser().getDotId());
        torderFee_by.setCreateUserId(ShiroKit.getUser().getId());
        torderFee_by.setAuditStatus(OrderFeeEnum.AUDIT_BALANCE.getCode());
        torderFee_by.setFeeId(OrderFeeEnum.SENDER_BY_FEE.getCode());
        torderFee_by.setMoney(0.0);
        tOrderFees.add(torderFee_by);
        itOrderFeeService.insertBatch(tOrderFees);
        //新增配送费用
        List<TOrderFee> tOrderFeeReceivers=new ArrayList<TOrderFee>();
        //配送提付
        TOrderFee torderFee_ps_tff=new TOrderFee();
        torderFee_ps_tff.setOrderId(tOrderSub.getId());
        torderFee_ps_tff.setDetpId(ShiroKit.getUser().getDeptId());
        torderFee_ps_tff.setDotId(ShiroKit.getUser().getDotId());
        torderFee_ps_tff.setCreateUserId(ShiroKit.getUser().getId());
        torderFee_ps_tff.setAuditStatus(OrderFeeEnum.AUDIT_UNBALANCE.getCode());
        torderFee_ps_tff.setFeeId(OrderFeeEnum.DELIVERY_TF_FEE.getCode());
        torderFee_ps_tff.setMoney(tff);
        tOrderFeeReceivers.add(torderFee_ps_tff);
        //配送代收货款
        TOrderFee torderFee_ps_dshk=new TOrderFee();
        torderFee_ps_dshk.setOrderId(tOrderSub.getId());
        torderFee_ps_dshk.setDetpId(ShiroKit.getUser().getDeptId());
        torderFee_ps_dshk.setDotId(ShiroKit.getUser().getDotId());
        torderFee_ps_dshk.setCreateUserId(ShiroKit.getUser().getId());
        torderFee_ps_dshk.setAuditStatus(OrderFeeEnum.AUDIT_UNBALANCE.getCode());
        torderFee_ps_dshk.setFeeId(OrderFeeEnum.DELIVERY_DSHK_FEE.getCode());
        torderFee_ps_dshk.setMoney(dshk);
        tOrderFeeReceivers.add(torderFee_ps_dshk);
        //配送落地费
        TOrderFee torderFee_ps_ldf=new TOrderFee();
        torderFee_ps_ldf.setOrderId(tOrderSub.getId());
        torderFee_ps_ldf.setDetpId(ShiroKit.getUser().getDeptId());
        torderFee_ps_ldf.setDotId(ShiroKit.getUser().getDotId());
        torderFee_ps_ldf.setCreateUserId(ShiroKit.getUser().getId());
        torderFee_ps_ldf.setAuditStatus(OrderFeeEnum.AUDIT_UNBALANCE.getCode());
        torderFee_ps_ldf.setFeeId(OrderFeeEnum.DELIVERY_LD_FEE.getCode());
        torderFee_ps_ldf.setMoney(ldf);
        tOrderFeeReceivers.add(torderFee_ps_ldf);
        //送货费
        TOrderFee torderFee_ps_shf=new TOrderFee();
        torderFee_ps_shf.setOrderId(tOrderSub.getId());
        torderFee_ps_shf.setDetpId(ShiroKit.getUser().getDeptId());
        torderFee_ps_shf.setDotId(ShiroKit.getUser().getDotId());
        torderFee_ps_shf.setCreateUserId(ShiroKit.getUser().getId());
        torderFee_ps_shf.setAuditStatus(OrderFeeEnum.AUDIT_UNBALANCE.getCode());
        torderFee_ps_shf.setFeeId(OrderFeeEnum.DELIVERY_SH_FEE.getCode());
        torderFee_ps_shf.setMoney(shf);
        tOrderFeeReceivers.add(torderFee_ps_shf);
        //搬运费
        TOrderFee torderFee_ps_by=new TOrderFee();
        torderFee_ps_by.setOrderId(tOrderSub.getId());
        torderFee_ps_by.setDetpId(ShiroKit.getUser().getDeptId());
        torderFee_ps_by.setDotId(ShiroKit.getUser().getDotId());
        torderFee_ps_by.setCreateUserId(ShiroKit.getUser().getId());
        torderFee_ps_by.setAuditStatus(OrderFeeEnum.AUDIT_UNBALANCE.getCode());
        torderFee_ps_by.setFeeId(OrderFeeEnum.DELIVERY_BY_FEE.getCode());
        torderFee_ps_by.setMoney(byf);
        tOrderFeeReceivers.add(torderFee_ps_by);
        //仓储费
        TOrderFee torderFee_ps_cc=new TOrderFee();
        torderFee_ps_cc.setOrderId(tOrderSub.getId());
        torderFee_ps_cc.setDetpId(ShiroKit.getUser().getDeptId());
        torderFee_ps_cc.setDotId(ShiroKit.getUser().getDotId());
        torderFee_ps_cc.setCreateUserId(ShiroKit.getUser().getId());
        torderFee_ps_cc.setAuditStatus(OrderFeeEnum.AUDIT_UNBALANCE.getCode());
        torderFee_ps_cc.setFeeId(OrderFeeEnum.DELIVERY_CC_FEE.getCode());
        torderFee_ps_cc.setMoney(ccf);
        tOrderFeeReceivers.add(torderFee_ps_cc);
        itOrderFeeService.insertBatch(tOrderFeeReceivers);
    }
}
